home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Magazin/MacEasy 30
/
Mac Magazin and MacEasy Magazine CD - Issue 30.iso
/
utilities
/
Mac OS X
/
Flurry
/
Flurry source
/
Source Folder
/
Star.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2001-04-17
|
3KB
|
136 lines
// Star.cpp: implementation of the Star class.
//
//////////////////////////////////////////////////////////////////////
#include "std.h"
#include "Star.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Star::Star()
{
mystery = 0.0f;//2323.2323f;
}
Star::~Star()
{
}
void Star::Draw()
{
return;
float width,sx,sy;
float w,z;
if (ate == false)
return;
width = 50000.0f * sys_glWidth / 1024.0f;
z = position[2];
sx = position[0] * sys_glWidth / z + sys_glWidth * 0.5f;
sy = position[1] * sys_glWidth / z + sys_glHeight * 0.5f;
w = width*4.0f / z;
float screenx = sx;
float screeny = sy;
const float black[4] = {0.0f,0.0f,0.0f,1.0f};
glPushMatrix();
glTranslatef(screenx,screeny,0.0f);
float scale = w/100.0f;
glScalef(scale,scale,0.0f);
float a;
float c = 0.08f;
float r,g,b;
for (int k=0;k<30;k++)
{
a = ((float) (rand() % 3600)) / 10.0f;
glRotatef(a,0.0f,0.0f,1.0f);
glBegin(GL_QUAD_STRIP);
glColor4fv(black);
glVertex2f(-3.0f,0.0f);
a = 3.0f + (float) (rand() & 2047) * c;
glVertex2f(-3.0f,a);
r = 0.125f + (float) (rand() % 875) / 1000.0f;
g = 0.125f + (float) (rand() % 875) / 1000.0f;
b = 0.125f + (float) (rand() % 875) / 1000.0f;
glColor4f(r,g,b,1.0f);
glVertex2f(0.0f,0.0f);
glColor4fv(black);
glVertex2f(0.0f,a);
glVertex2f(3.0f,0.0f);
glVertex2f(3.0f,a);
glEnd();
}
glPopMatrix();
}
#define BIGMYSTERY 1800.0
#define MAXANGLES 16384
void Star::Update()
{
const float rotationsPerSecond = (float) (2.0*PI*TICKSPERSECOND/MAXANGLES) * 0.5f /* speed control */;
double thisPointInRadians;
double thisAngle = fTime*rotationsPerSecond;
float cf;
int i;
double tmpX1,tmpY1,tmpZ1;
double tmpX2,tmpY2,tmpZ2;
double tmpX3,tmpY3,tmpZ3;
double tmpX4,tmpY4,tmpZ4;
double rotation;
double cr;
double sr;
// float mystery = 2323.2323f;
float old[3];
ate = false;
for (i=0;i<3;i++)
{
old[i] = position[i];
}
cf = ((float) (cos(7.0*((fTime)*rotationsPerSecond))+cos(3.0*((fTime)*rotationsPerSecond))+cos(13.0*((fTime)*rotationsPerSecond))));
cf /= 6.0f;
cf += 0.75f; // 0.25 - 1.25
thisPointInRadians = 2.0 * PI * (double) mystery / (double) BIGMYSTERY;
position[0] = 250.0f * cf * (float) cos(11.0 * (thisPointInRadians + (3.0*thisAngle)));
position[1] = 250.0f * cf * (float) sin(12.0 * (thisPointInRadians + (4.0*thisAngle)));
position[2] = 250.0f * (float) cos((23.0 * (thisPointInRadians + (12.0*thisAngle))));
rotation = thisAngle*0.501 + 5.01 * (double) mystery / (double) BIGMYSTERY;
cr = cos(rotation);
sr = sin(rotation);
tmpX1 = position[0] * cr - position[1] * sr;
tmpY1 = position[1] * cr + position[0] * sr;
tmpZ1 = position[2];
tmpX2 = tmpX1 * cr - tmpZ1 * sr;
tmpY2 = tmpY1;
tmpZ2 = tmpZ1 * cr + tmpX1 * sr;
tmpX3 = tmpX2;
tmpY3 = tmpY2 * cr - tmpZ2 * sr;
tmpZ3 = tmpZ2 * cr + tmpY2 * sr + seraphDistance;
rotation = thisAngle*2.501 + 85.01 * (double) mystery / (double) BIGMYSTERY;
cr = cos(rotation);
sr = sin(rotation);
tmpX4 = tmpX3 * cr - tmpY3 * sr;
tmpY4 = tmpY3 * cr + tmpX3 * sr;
tmpZ4 = tmpZ3;
position[0] = (float) tmpX4;
position[1] = (float) tmpY4;
position[2] = (float) tmpZ4;
}